package main

import (
	"encoding/xml"
	"fmt"
	"io"
	"os"
)

type Node interface {
}
type CharData string
type Element struct {
	Type     xml.Name
	Attr     []xml.Attr
	Children []Node
}

func buildNodeTree(dec *xml.Decoder) (*Element, error) {
	root := &Element{}
	var stack []*Element

	for {
		tok, err := dec.Token()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, err
		}
		switch tok := tok.(type) {
		case xml.StartElement:
			elem := &Element{Type: tok.Name, Attr: tok.Attr}
			if len(stack) > 0 {
				stack[len(stack)-1].Children = append(stack[len(stack)-1].Children, elem)
			}
			stack = append(stack, elem)
			fmt.Printf("sta:%*s%s\n", len(stack)*2, "", elem.Type.Local)
		case xml.EndElement:
			if len(stack) == 1 {
				root = stack[0]
			}
			if len(stack) > 0 {
				stack = stack[:len(stack)-1]
			}
			fmt.Printf("end:%*s%s\n", len(stack)*2, "", tok.Name.Local)
		case xml.CharData:
			if len(stack) > 0 {
				stack[len(stack)-1].Children = append(stack[len(stack)-1].Children, CharData(tok.Copy()))
			}
			fmt.Printf("cha:%*s%s\n", len(stack)*2, "", string(tok.Copy()))
		}
	}
	return root, nil
}
func main() {
	dec := xml.NewDecoder(os.Stdin)
	tree, err := buildNodeTree(dec)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error building node tree from XML: %v", err)
		os.Exit(1)
	}
	printNodeTree(tree, 0)
}
func printNodeTree(node *Element, indent int) {
	if node == nil {
		return
	}
	fmt.Printf("%*s%s\n", indent, "", node.Type.Local)
	indent += 2
	for _, attr := range node.Attr {
		fmt.Printf("%*s%s='%s'\n", indent, "", attr.Name.Local, attr.Value)
	}
	for _, child := range node.Children {
		switch child := child.(type) {
		case *Element:
			printNodeTree(child, indent)
		case CharData:
			fmt.Printf("%*s%s\n", indent, "", string(child))
		}
	}
	indent -= 2
}
